package org.zfes.snowier.cloud.zbss.widget.act.route.service.tea;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.ComboboVo;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.widget.act.model.ActQuestion;
import org.zfes.snowier.cloud.zbss.widget.act.service.IActQuestionDifficultyService;
import org.zfes.snowier.cloud.zbss.widget.act.service.IActQuestionService;
@Controller("org.zfes.snowier.cloud.zbss.widget.act.route.service.tea.actQuestionController") 
@RequestMapping("/active/service/tea/actQuestion")
public class ActQuestionController extends BaseController {
	
	@Autowired
	private IActQuestionService actQuestionService;
	@Autowired
	private IActQuestionDifficultyService actQuestionDifficultyService;
	
	
    @RequestMapping(value="/loadActQuestionDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadActQuestionDataSet(@RequestParam Map<String,Object> params){
    	params.put("creatorUserId", SecurityUtil.getUserId().orElse(null));
    	params.put("status", Byte.valueOf("1"));
    	DataSet dataSet=  actQuestionService.loadActQuestionDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
    @RequestMapping(value="/createActQuestion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createActQuestion(ActQuestion actQuestion){
		actQuestionService.createActQuestion(actQuestion);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/loadActQuestion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadActQuestion(Long id){
		Optional<ActQuestion> ops = actQuestionService.loadActQuestionById(id);
		return ajaxQuery("actQuestion",ops);
    }
	
    @RequestMapping(value="/updateActQuestion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateActQuestion(ActQuestion actQuestion){
		actQuestionService.updateActQuestion(actQuestion);
		return ajaxDoneSuccess("数据操作成功 ");
    }

    @RequestMapping(value="/deleteActQuestion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteActQuestion(Long id){
		actQuestionService.setActQuestionStatus(id, Byte.valueOf("-1"));
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    @RequestMapping(value="/loadQuesDifComboboVo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadQuesDifComboboVo(Boolean firstEmpty){
    	 List<ComboboVo> comboboVo= actQuestionDifficultyService.loadComboboVo(firstEmpty);
		return ajaxQuery("comboboVo", comboboVo);
    }
}